package com.sfac.javaSpringBoot.modules.test.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sfac.javaSpringBoot.modules.common.entity.AbstractEntity;

import javax.persistence.*;
import java.util.List;

@Entity//表明是一个实体类
@Table(name="test_student")//生成的表名
public class Student extends AbstractEntity {
    private String name;
    private String email;
    private Integer age;
    /**
     * OneToOne：一对一关系中，有外键方使用 JoinColumn 注解，另一方使用 mappedBy 属性（可选）
     * targetEntity：目标实体
     * cascade：联级操作
     * fetch：加载数据策略
     * JoinColumn
     * name 对应 test_student 表中 card_id 外键列
     */
    @OneToOne(targetEntity = Card.class,cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "card_id",unique = true)//注释本表中指向另一个表的外键
    private Card studentCard;
    /**
     * ManyToMany，一方使用 JoinTable 注解，另一方配置 mappedBy 属性
     * cascade：联级操作
     * fetch：加载数据策略
     * JsonIgnore：不序列化该字段，避免无限递归
     */
    @ManyToMany(mappedBy = "students",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JsonIgnore
    private List<Clazz> clazzes;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getAge() {
        return age;
    }

    public List<Clazz> getClazzes() {
        return clazzes;
    }

    public void setClazzes(List<Clazz> clazzes) {
        this.clazzes = clazzes;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Card getStudentCard() {
        return studentCard;
    }

    public void setStudentCard(Card studentCard) {
        this.studentCard = studentCard;
    }
}
